var dq = document.getElementById('disqus_thread');
var sbd = document.getElementById('sbd');
var dialogstate = 'brstt';
if(sbd) {
	var ww = window.innerWidth;
	var wr = document.getElementById('wrap').offsetWidth;
	var wf = ww - wr;
	sbd.style.left = (wf/2)-100 + 'px';
}

function abd(e) {
	console.log('true');
	for(i=0; i<=document.querySelectorAll('.ad').length; i++) {
		el = document.getElementsByClassName(e)[i];
		if(el) {
			var elp = el.parentNode;
			if(el.offsetHeight === 0) {
				var els = document.createElement('div');
				els.className = 'basic-box';
				var elsc = document.createTextNode('Hey, ad blocker user! If you found my writings useful, please consider white listing this site. Thanks :)');
				els.appendChild(elsc);
				elp.appendChild(els);
			}
		}
	}
}

function script(e) {
	var t = document.createElement("script");
	t.type = "text/javascript";
	t.async = true;
	t.src = e;
	var n = document.getElementsByTagName("head")[0];
	n.appendChild(t)
}

function getCookie(name) {
	var re = new RegExp(name + "=([^;]+)");
	var value = re.exec(document.cookie);
	return (value != null) ? unescape(value[1]) : null;
}

function loadScripts() {
	if(dq) load_disqus();
	abd('ad');
	prettyPrint();
	script('https://apis.google.com/js/plusone.js');
	script('https://connect.facebook.net/en_US/all.js#xfbml=1');
	script('https://platform.twitter.com/widgets.js');
	script('https://assets.pinterest.com/js/pinit.js');
	//if(!getCookie('brstt')) createDialog();
}

function load_disqus() {
	var e = "bloggerrecipes";
	(function () {
		var t = document.createElement("script");
		t.type  = "text/javascript";
		t.async = true;
		t.src   = "http://" + e + ".disqus.com/embed.js";
		(document.getElementsByTagName("head")[0] || document.getElementsByTagName("body")[0]).appendChild(t)
	})();
}

function createDialog() {
	var dialogwrap = document.createElement('div');
	dialogwrap.className = 'dialogwrap';
	dialogwrap.setAttribute('id', 'thedialog');
	var dialog = document.createElement('div');
	dialog.className = 'dialog';
	dialog.className += ' clearfix';
	dialog.innerHTML = '<div class="dialoginner"><div class="widget-title">Support us</div><div class="g-page" data-href="https://plus.google.com/113823068212307603515" data-layout="landscape" data-rel="publisher"></div><button class="close" onclick="destroyDialog()">X</button></div>';
	dialogwrap.appendChild(dialog);
	document.body.appendChild(dialogwrap);
}

function destroyDialog() {
	var dialogwrap = document.getElementById('thedialog');
	dialogwrap.parentNode.removeChild(dialogwrap);
	document.cookie=dialogstate + "=; path=/; expires=" + expiry.toGMTString();
}

window.onload = loadScripts();